package com.web.base.auth.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.blue.jdbc.JdbcDataSource;
import com.blue.jdbc.Page;
import com.web.base.auth.dao.AppDao;
import com.web.base.auth.model.App;
import com.web.base.auth.exception.AppException;
import com.web.core.util.Const;

/**
 * 应用业务层
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月15日
 */
@Service
@Transactional
@JdbcDataSource(Const.DS_BASE)
public class AppService
{
	@Resource
	private AppDao appDao;
	
	public AppService()
	{
	}
	
	public App save(App app)
	{
		if (appDao.exist(app, "code"))
			throw new AppException("应用代码已经存在：" + app.getCode());
		
		if (appDao.exist(app, "name"))
			throw new AppException("应用名称已经存在：" + app.getName());
		
		if (app.getId() == null)
		{
			appDao.save(app);
		}
		else
		{
			appDao.update(app);
		}
		App a = appDao.get(app.getId());
		return a;
	}
	
	public App get(Integer id)
	{
		App log = appDao.get(id);
		return log;
	}
	
	public Page<App> list(App app, Page<App> page)
	{
		page = appDao.list(app, page);
		return page;
	}
	
	public List<App> list(App app)
	{
		List<App> list = appDao.list(app);
		return list;
	}
	
	public void delete(App app)
	{
		appDao.delete(app);
	}
	
}
